/**
 * Qiangungun.com Inc.
 * Copyright (c) 2015-2015 All Rights Reserved.
 */
package com.qiangungun.report.biz.task.processor;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.util.Assert;

import com.qiangungun.report.core.cache.Cache;

/**
 * 初始化配置加载
 * @author hangdahong
 * @version $Id: CacheTaskStartup.java, v 0.1 2015年3月5日 下午2:36:46 hangdahong Exp $
 */
public class CacheTaskStartup implements ApplicationListener<ContextRefreshedEvent>,
                             ApplicationContextAware {

    private static final Logger logger = LoggerFactory
            .getLogger(CacheTaskStartup.class);

    
    private List<Cache<?,?>> caches;
    
    /** 
     * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
     */
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        //NOOP
    }

    /** 
     * @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent)
     */
    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        logger.info("开始加载报表配置");
        Assert.notNull(caches);
        for(Cache<?,?> cache:caches){
            cache.init();
        }
        logger.info("加载报表配置完毕");
    }

    /**
     * Setter method for property <tt>caches</tt>.
     * 
     * @param caches value to be assigned to property caches
     */
    public void setCaches(List<Cache<?,?>> caches) {
        this.caches = caches;
    }
    
    

}
